﻿<%@ Page Language="C#" %>

<%
    int index = Int16.Parse(Request["index"]);
    int btnDel = Int16.Parse(Request["btnDel"]);
    if (btnDel == 1)
    {
        DTO.GioHangDTO GioHang = (DTO.GioHangDTO)Session["GioHang"];
        GioHang.lstHang.RemoveAt(index);
        GioHang.Gianhangvaomua.RemoveAt(index);
        if (GioHang.lstHang.Count == 0)
        {
            Session["GioHang"] = null;
            Response.Write("-1");
        }
        else
        {
            Response.Write("<table width='100%' border='0' align='center' cellpadding='4' cellspacing='0'><tr><td class='table_header'>Giỏ hàng</td></tr><tr><td><br /><table width='95%' border='1' align='center' cellpadding='4' cellspacing='0' id='table_GioHang'><tr><td class='giohang_Header'>STT</td><td class='giohang_Header'>Tên sản phẩm</td><td class='giohang_Header'>Số lượng</td><td class='giohang_Header'>Đơn giá (ngàn)</td><td class='giohang_Header'>Thành tiền (ngàn)</td><td class='giohang_Header'>Xóa</td></tr>");
            long ThanhTien = 0;
            long TongThanhTien = 0;
            int j;
            for (int i = 0; i < GioHang.lstHang.Count; i++)
            {
                j = i + 1;
                ThanhTien = GioHang.lstHang[i].SoLuong * GioHang.lstHang[i].GiaBanHienTai;
                TongThanhTien += ThanhTien;
                if (GioHang.lstHang[i].MaDanhMucSanPham == 1)
                {
                    Response.Write("<tr><td>" + j + "</td><td><a href='ChiTietLapTop.aspx?itemID=" + GioHang.lstHang[i].ID + "'><img class='hangTrongGio' src='" + GioHang.lstHang[i].HinhSanPham + "' alt='' border='0'/></a><div style='padding-top:20px'><a class='linkStyle' href='ChiTietLapTop.aspx?itemID=" + GioHang.lstHang[i].ID + "'>" + GioHang.lstHang[i].TenSanPham + "</a></div></td><td><input type='text' size='2' ID='txtSoLuong" + i + "' value='" + GioHang.lstHang[i].SoLuong + "' Width='30px' onKeyUp='changeQuantity(" + i + ");'/></td><td>" + GioHang.lstHang[i].GiaBanHienTai + "<td>" + ThanhTien + "</td><td><img src='images/cancel_48.png' width='20' height='20' alt='' onclick='delProduct(" + i + ");' /></td></tr>");
                }
                else if (GioHang.lstHang[i].MaDanhMucSanPham == 2)
                {
                    Response.Write("<tr><td>" + j + "</td><td><a href='ChiTietDienThoai.aspx?itemID=" + GioHang.lstHang[i].ID + "'><img class='hangTrongGio' src='" + GioHang.lstHang[i].HinhSanPham + "' alt='' border='0'/></a><div style='padding-top:20px'><a class='linkStyle' href='ChiTietDienThoai.aspx?itemID=" + GioHang.lstHang[i].ID + "'>" + GioHang.lstHang[i].TenSanPham + "</a></div></td><td><input type='text' size='2' ID='txtSoLuong" + i + "' value='" + GioHang.lstHang[i].SoLuong + "' Width='30px' onKeyUp='changeQuantity(" + i + ");'/></td><td>" + GioHang.lstHang[i].GiaBanHienTai + "<td>" + ThanhTien + "</td><td><img src='images/cancel_48.png' width='20' height='20' alt='' onclick='delProduct(" + i + ");' /></td></tr>");
                }
            }
            GioHang.ThanhTien = TongThanhTien;
            Response.Write("<tr><td colspan='4' class='totalCostText'>Tổng thành tiền:</td><td class='totalCost' colspan='3'>" + GioHang.ThanhTien + "</td><td></td></tr>");
            Session["GioHang"] = GioHang;
        }
    }
        %>
